package flc.ast.adapter;

import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.activity.PasswordActivity;
import flc.ast.bean.MyPassKindBean;
import flc.ast.bean.MyPassRecordBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class PasswordAdapter extends StkProviderMultiAdapter<MyPassRecordBean> {

    public PasswordAdapter() {
        addItemProvider(new StkSingleSpanProvider(30));
        addItemProvider(new PasswordProvider());
    }

    private boolean isEdit;

    public boolean isEdit() {
        return isEdit;
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class PasswordProvider extends BaseItemProvider<MyPassRecordBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_password;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyPassRecordBean bean) {
            baseViewHolder.setImageResource(R.id.ivPasswordItemImg, PasswordActivity.kindBean.getImg());
            baseViewHolder.setText(R.id.tvPasswordItemName, bean.getName());
            baseViewHolder.setText(R.id.tvPasswordItemAccount, bean.getAccount());
            if (isEdit) {
                baseViewHolder.getView(R.id.ivPasswordItemIcon).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivPasswordItemDelete).setVisibility(View.VISIBLE);
            } else{
                baseViewHolder.getView(R.id.ivPasswordItemIcon).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivPasswordItemDelete).setVisibility(View.GONE);
            }
        }
    }
}
